package com.lqd.mall.system;

import com.lqd.mall.interaction.system.SysLogininforEntity;
import com.lqd.mall.redis.utils.RedisUtils;
import com.lqd.mall.system.repository.SysLogininforEntityRepository;
import com.lqd.mall.system.service.ISysLogininforService;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @author 零起点
 * @create 2022-02-12 15:51
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class SystemTestApplication {

    @Autowired
    private RedisUtils redisUtils;


    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Resource
    SysLogininforEntityRepository sysLogininforEntityRepository;
    @Resource
    ISysLogininforService sysLogininforService;

    @Test
    public void TestApplication() {
        sysLogininforEntityRepository.delectEntity(new SysLogininforEntity().setInfoId(1L));
        System.out.println();
    }

    @Test
    public void testISysLogininforService() {
        SysLogininforEntity entity = new SysLogininforEntity().setInfoId(1L);
        entity.setMsg("测试更新2022年3月11日");
        Optional<Integer> infoId = sysLogininforService.updateEntity(entity, "info_id");
        System.out.println(infoId);
    }

    @Test
    public void testRedisTemplate() {
     /*  List<String> newList = new ArrayList();
        newList.add("o");
        newList.add("p");
        newList.add("q");
        newList.forEach(item->{
            redisTemplate.opsForList().leftPush("list",item);
        }); */
        redisTemplate.opsForList().remove("list",1,"o");
        // 先取出来
  /*    List<Object> list = redisTemplate.opsForList().range("list", 0, -1);
        // 删除
        list.remove(3);

        ListOperations<String, Object> opsForList = redisTemplate.opsForList();
       // 删除redis 缓存
        Object o1 = opsForList.rightPop("list");
        // 存储进去
        for (Object object : list){
            redisTemplate.opsForList().leftPush("list",object);
        }*/

      /*  Long tian = redisTemplate.opsForValue().getOperations().getExpire("tian");   // 单个

        tian = tian + 1000 * 60 * 60 * 3;
        redisTemplate.expire("tian", tian, TimeUnit.MILLISECONDS);

        
        redisTemplate.opsForValue().getOperations();
        redisUtils.set("测试","100",1000);
        Long expire = redisTemplate.opsForList().getOperations().getExpire("list");  // list*/

        /*List<Object> idList = Arrays.asList(9, 50, 10, 30,50,9);
        List<User> users = new ArrayList<>();
        users.add(new User(50, "寇淇芮", "20"));
        users.add(new User(30, "dome01", "20"));
        users.add(new User(10, "dome010", "20"));
        users.add(new User(9, "dome0101", "20"));
        Map<Integer, User> listMap = users.stream().collect(Collectors.toMap(User::getId,item->item));
        List<User> userList = new ArrayList<>();
        idList.forEach(item -> {
            User orDefault = listMap.getOrDefault(item, null);
            if (orDefault != null) {
                userList.add( orDefault);
            }
        });
        System.out.println(userList);*/
    }


}

@Getter
@Setter
@AllArgsConstructor
@ToString
class User {
    private Integer id;
    private String name;
    private String age;
}
